﻿using System;
using System.Web;
using gms.data;
using gms.system;

namespace gms.security {
	public static class Authorization {
		public static void AuthorizeOrForward(AclType types, string redirect_to = null) {
			if (!IsAuthorized(types)) {
				if (redirect_to != null) {
					HttpContext.Current.Response.Redirect(redirect_to);
				}
				else {
					HttpContext.Current.Response.Redirect("/login.aspx");
				}
			}
		}
		public static bool IsAuthorized(AclType types) {
			Authentication.MustBeAuthed();

			Player checker = Player.load_by_id(Authentication.AuthedPlayer);

			if (checker.test(types)) {
				return true;
			}
			else {
				return false;
			}
		}
	}
}